import 'dart:async';
// import 'package:iea/models/personalPage_models/personalPage_model.dart';
// import 'package:iea/models/personalPage_models/personalPage_model.dart';
import 'package:iea/provider/base/base_resp.dart';
import 'package:iea/provider/resource/personalPage_api_provider.dart';

class PersonalPageBloc {
  final _apiClient = PersonalPageApiProvider();

  StreamSubscription<BaseResp> _saveSubscription;
  final StreamController<BaseResp> _saveController =StreamController<BaseResp>.broadcast();
  Stream<BaseResp> get saveInfoStream => _saveController.stream;

  /*
  *  上传图片
  * @links
  */
  // void uploadImgUrl(file) {
  //   _uploadImgUrlSubscription?.cancel();
  //   _uploadImgUrlSubscription =
  //       _apiClient.uploadImgUrl(file).asStream().listen((BaseResp data) {
  //        if (data.result) {
  //          print(data);
  //     }
  //     _uploadImgUrlController.add(data);
  //   });
  // }
  
  /*
  *  修改个人信息
  * @links
  */
  // void updateUserInformation([params]) {
  //   _uploadImgUrlSubscription?.cancel();
  //   _uploadImgUrlSubscription =_apiClient.updateUserInformation(params).asStream().listen((BaseResp data) {
  //     if (data.result) {
  //       // data.data = PersonalPageModel.fromJson(data.data);
  //     }
  //     _uploadImgUrlController.add(data);
  //   });
  // }

  void updateUserInformation([params]) {
    _saveSubscription?.cancel();
    _saveSubscription =_apiClient.updateUserInformation(params).asStream().listen((BaseResp data) {
      if (data.result) {
        // data.data = PersonalPageModel.fromJson(data.data);
      }
      _saveController.add(data);
    });
  }


  void dispose() {
    _saveSubscription?.cancel();
    _saveController.close();
  }
}
